package com.qf.controller;

import com.qf.dto.R;
import com.qf.pojo.Scene;
import com.qf.pojo.User;
import com.qf.service.SceneService;
import com.qf.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
杨威
2022/1/2
17:30
*/
@RestController
@RequestMapping("/scene")
public class SceneController {
    @Autowired
    private SceneService sceneService;
    @RequestMapping("/addScene")
    public R add(@RequestBody Scene scene){
        sceneService.addScene(scene);
        return R.setOk();
    }

    @RequestMapping("/select")
    public R selectByUser(){
        User user = SecurityUtils.getUser();
        List<Scene> sceneList = sceneService.findByUserId(user.getUId());
        return R.setOk(sceneList);

    }

    @RequestMapping("/deleteScenes")
    public R deleteByIds(@RequestBody List<Long> ids){
        int i = sceneService.deleteByIds(ids);
        return R.setOk();
    }
}
